﻿using System;
using System.Collections.Generic;
using Shutterstock.Salesforce.Tools.SFPartner;
using System.Data;

namespace Shutterstock.Salesforce.SSISDownload
{
    public static class SFTypeConverter
    {
        private static Dictionary<fieldType, SqlDbType> _toSqlDBTypes;
        private static Dictionary<fieldType, Type> _toTypes;


        public static SqlDbType ConvertToSqlDBType(fieldType SFtype)
        {
            return _toSqlDBTypes[SFtype];
        }

        public static Type ConvertToType(fieldType SFtype)
        {
            return _toTypes[SFtype];
        }

        static SFTypeConverter()
        {
            _toSqlDBTypes = new Dictionary<fieldType, SqlDbType>();
            _toTypes = new Dictionary<fieldType, Type>();
            
            _toSqlDBTypes.Add(fieldType.anyType, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.base64, SqlDbType.VarBinary);
            _toSqlDBTypes.Add(fieldType.boolean, SqlDbType.Bit);
            _toSqlDBTypes.Add(fieldType.combobox, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.currency, SqlDbType.Decimal);
            _toSqlDBTypes.Add(fieldType.datacategorygroupreference, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.date, SqlDbType.DateTime);
            _toSqlDBTypes.Add(fieldType.datetime, SqlDbType.DateTime);
            _toSqlDBTypes.Add(fieldType.@double, SqlDbType.Decimal);
            _toSqlDBTypes.Add(fieldType.email, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.encryptedstring, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.id, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.@int, SqlDbType.Int);
            _toSqlDBTypes.Add(fieldType.multipicklist, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.percent, SqlDbType.Float);
            _toSqlDBTypes.Add(fieldType.phone, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.picklist, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.reference, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.@string, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.textarea, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.url, SqlDbType.NVarChar);
            _toSqlDBTypes.Add(fieldType.time, SqlDbType.NVarChar);


            
            _toTypes.Add(fieldType.anyType, typeof(string));
            _toTypes.Add(fieldType.base64, typeof(byte[]));
            _toTypes.Add(fieldType.boolean, typeof(bool));
            _toTypes.Add(fieldType.combobox, typeof(string));
            _toTypes.Add(fieldType.currency, typeof(decimal));
            _toTypes.Add(fieldType.date, typeof(DateTime));
            _toTypes.Add(fieldType.datetime, typeof(DateTime));
            _toTypes.Add(fieldType.datacategorygroupreference, typeof(string));
            _toTypes.Add(fieldType.@double, typeof(Decimal));
            _toTypes.Add(fieldType.email, typeof(string));
            _toTypes.Add(fieldType.encryptedstring, typeof(string));
            _toTypes.Add(fieldType.id, typeof(string));
            _toTypes.Add(fieldType.@int, typeof(int));
            _toTypes.Add(fieldType.multipicklist, typeof(string));
            _toTypes.Add(fieldType.percent, typeof(float));
            _toTypes.Add(fieldType.phone, typeof(string));
            _toTypes.Add(fieldType.picklist, typeof(string));
            _toTypes.Add(fieldType.reference, typeof(string));
            _toTypes.Add(fieldType.@string, typeof(string));
            _toTypes.Add(fieldType.textarea, typeof(string));
            _toTypes.Add(fieldType.url, typeof(string));
            _toTypes.Add(fieldType.time, typeof(string));
        }
    }


    
}
